

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyNotification extends Notification {
  String? msg;
  MyNotification({this.msg});
}

class ParentNotificationWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ParentNotificationState();
  }



}

class _ParentNotificationState extends State<ParentNotificationWidget>{
  String? _msg;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("ParentNotificationWidget"),
      ),
      body: NotificationListener<MyNotification>(
        onNotification: (noti){
          setState(() {
            _msg = noti.msg;
          });
          return true;
        },
        child: Center(
          child: Column(
            children: [
              Builder(
                builder: (content){
                  return RaisedButton(onPressed: (){
                    MyNotification(msg: "平级发送").dispatch(context);
                  },
                  child: Text("发通知"),
                  );
                },
              ),
              Text(_msg??"null"),
            ],
          ),
        ),
      ),

    );
  }

}